<html>
<head>
    <title>吉垚物业后台管理系统</title>
    <meta charset="utf-8">
    <link rel="shortcut icon" th:href="./images/favicon.ico" type="image/x-icon">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <!-- 引入css -->
    <link rel="stylesheet" href="./css/plugins/font-awesome-4.7.0/css/font-awesome.min.css"  media="all">
    <link rel="stylesheet" href="./lib/layui-v2.3.0/css/layui.css"  media="all">
    <link rel="stylesheet" href="./css/main.css"  media="all">
    <link rel="stylesheet" href="./lib/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
</head>
<body class="timo-layout-page">
    <div class="layui-card">
        <div class="layui-card-header timo-card-header">
            <span><i class="fa fa-bars"></i> 招聘信息管理</span>
            <i class="layui-icon layui-icon-refresh refresh-btn"></i>
        </div>
        <div class="layui-card-body">
            <div class="layui-row timo-card-screen put-row">
                <div class="pull-right screen-btn-group">
                    <div class="btn-group-right" id="controlD">
                        <button class="layui-btn open-popup" data-title="添加类型" data-size="600,520" data-url="popupAdv.html">
                            <i class="fa fa-plus"></i>添加</button>
                    </div>
                </div>
            </div>
            <table class="layui-table ">
                <thead>
                <tr>
                    <th>岗位</th>
                    <th>薪资</th>
                    <th>岗位简介</th>
                    <th>工作地址</th>
                    <th>隶属部门</th>
                    <th>工作性质</th>
                    <th>经验要求</th>
                    <th>年龄要求</th>
                    <th>性别要求</th>
                    <th>具体描述</th>
                    <th>福利待遇</th>
                    <th>联系方式</th>
                    <th>创建时间</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="advs">
<!--                <tr>-->
<!--                    <td><label class="timo-checkbox"><input type="checkbox" value="1">-->
<!--                        <i class="layui-icon layui-icon-ok"></i></label></td>-->
<!--                    <td>战略合作</td>-->
<!--                    <td>合作</td>-->
<!--                    <td>2020-03-12</td>-->
<!--                    <td>-->
<!--                        <a class="open-popup" data-title="编辑" data-size="600,570" href="#" data-url="404.html">编辑</a>-->
<!--                        <a class="ajax-get" href="/user/status/delete?ids=1" data-msg=确认删除">删除</a>-->
<!--                    </td>-->
<!--                </tr>-->
                </tbody>
            </table>
        </div>
<!--        <a class="open-popup" data-title="编辑" data-size="600,570" href="#" data-url="belong-main.html">测试</a>-->
    </div>
<script type="text/javascript" src="./lib/layui-v2.3.0/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/main.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/plugins/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="./lib/zTree_v3/js/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="./js/timoTree.js"></script>
    <script src="js/checkToken.js"></script>
<script type="text/javascript">
    var local = window.localStorage;
    // 树形菜单

var usertype=sessionStorage.getItem('usertype');
console.log('用户类型:'+usertype);

    getAdvs();
function getAdvs() {
    $('#advs').empty();
    $.ajax({
        url: 'http://localhost:8081/admin/getAdvs.do',
        headers:{
            accessToken:localStorage.getItem('accessToken')
        },
        success: function (data) {
           checkToken(data);
            for (var i = 0; i < data.result.length; i++) {
                var exp=data.result[i]['experiences'];var age=data.result[i]['agelimit'];var sex=data.result[i]['sex'];var benefit=data.result[i]['benefit'];
                switch (exp) {
                    case 0:exp='经验不限';break;
                    case 1:exp='一年经验以内';break;
                    case 2:exp='一到三年经验';break;
                    case 3:exp='三到五年经验';break;
                    case 4:exp='五年经验以上';break;
                }
                switch (age) {
                    case 0:age='年龄不限';break;
                    case 1:age='25以下';break;
                    case 2:age='35以下';break;
                    case 3:age='50以下';break;
                }
                switch (sex) {
                    case -1:sex='性别不限';break;
                    case 0:sex='仅限男性';break;
                    case 1:sex='仅限女性';break;
                }
                switch (benefit) {
                    case "-1":benefit='单休';break;
                    case "0":benefit='大小周';break;
                    case "1":benefit='双休';break;
                    case "2":benefit='五险一金，单休';break;
                    case "3":benefit='五险一金，双休';break;
                }
                $('#advs').append('<tr>\n' +
                    '                    <td>' + data.result[i]['name'] + '</td>\n' +
                    '                    <td>' + data.result[i]['salary'] +'</td>\n' +
                    '                    <td>' + data.result[i]['introduction'] + '</td>\n' +
                    '                    <td>' + data.result[i]['address'] + '</td>\n' +
                    '                    <td>' + data.result[i]['department'] + '</td>\n' +
                    '                    <td>' + data.result[i]['natureofwork'] + '</td>\n' +
                    '                    <td>' + exp + '</td>\n' +
                    '                    <td>' + age + '</td>\n' +
                    '                    <td>' + sex + '</td>\n' +
                    '                    <td>' + data.result[i]['describes'] + '</td>\n' +
                    '                    <td>' + benefit + '</td>\n' +
                    '                    <td>' + data.result[i]['telephone'] + '</td>\n' +
                    '                    <td>' + data.result[i]['createtime'] + '</td>\n' +
                    '                    <td>' + data.result[i]['updatetime'] + '</td>\n' +
                    '                    <td>\n' +
                    '                        <a class="open-popup" data-title="编辑" data-size="600,570" href="#" onclick="setVal(' + data.result[i]['id'] + ',\'' + data.result[i]['name'] + '\',\'' + data.result[i]['salary'] + '\',\'' + data.result[i]['introduction'] + '\',\''+data.result[i]['address']+'\',\''+data.result[i]['department']+'\',\''+data.result[i]['natureofwork']+'\','+data.result[i]['experiences']+','+data.result[i]['agelimit']+','+data.result[i]['sex']+',\''+data.result[i]['describes']+'\','+data.result[i]['benefit']+','+data.result[i]['telephone']+')" data-url="popupUpdateAdv.html">编辑</a>\n' +
                    '                        <a href="#" onclick="delAdv(' + data.result[i]['id'] + ')">删除</a>\n' +
                    '                    </td>\n' +
                    '                </tr>')
            }
        }
    })
}
    // <a class="ajax-get" href="#" onclick="delType('+data.result[i]['id']+')">

    function setVal(advid,name,salary,introduction,address,department,natureofwork,exp,age,sex,describes,benefit,telephone) {
    console.log('进入setVal')
        console.log('name:'+name);
        console.log('department:'+department);
        sessionStorage.setItem('advid',advid);
        sessionStorage.setItem('name',name);
        sessionStorage.setItem('salary',salary);
        sessionStorage.setItem('introduction',introduction);
        sessionStorage.setItem('address',address);
        sessionStorage.setItem('department',department);
        sessionStorage.setItem('natureofwork',natureofwork);
        sessionStorage.setItem('exp',exp);
        sessionStorage.setItem('age',age);
        sessionStorage.setItem('sex',sex);
        sessionStorage.setItem('describes',describes);
        sessionStorage.setItem('benefit',benefit);
        sessionStorage.setItem('telephone',telephone);
    }

function delAdv(advid){
    if (!confirm('确认删除?'))
        return;
    $.ajax({
        url:'http://localhost:8081/admin/delAdv.do?advid='+advid,
        headers:{
            accessToken:localStorage.getItem('accessToken')
        },
        success:function (data) {
            checkToken(data);
            // if (data.resMsg=='用户未登录'){
            //     sessionStorage.clear();
            //     top.location.href='notlogin.html';
            //     this.close();
            // }
            if (data.resMsg=='删除成功'){
                getAdvs();
            }else {
                alert('删除失败');
            }
        }
    })
}
    $.fn.selectTree({
        rootTree: '全部',
        onSelected: function(treeNode){
            local.setItem('deptTitle', treeNode.name);
        }
    });
    $(function(){
        var dept = $('.select-tree');
        if(dept.attr('value').length > 0){
            dept.val(local.getItem('deptTitle'));
        }
    });
</script>
</body>
</html>